/*
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef _WISHMASTER_CHANAGENT_H
#define _WISHMASTER_CHANAGENT_H

#include <QObject>
#include <QByteArray>
#include <QUrl>
#include "network/request.h"
#include "taskhub.h"
#include "components/postid.h"
#include "components/threadid.h"
#include "components/boardconstraints.h"
#include "misc.h"

namespace Wishmaster
{
	struct PostDescriptor;
	struct AttachmentDescriptor;

	struct BoardDescriptor
	{
		QString name;
		QString alias;
	};

	class Connector;
	class CaptchaFetcher;
	class CookieStorage;
	class WISHMASTER_EXPORT ChanAgent : public QObject
	{
		Q_OBJECT
	public:
		ChanAgent(const QString& host);
		virtual ~ChanAgent() {}

		virtual void setTaskhub(Taskhub* taskhub) = 0;
		virtual Taskhub* taskhub() = 0;

		virtual void setConnector(Connector* connector) = 0;
		virtual Connector* connector() const = 0;

		// Transfers ownership to ChanAgent
		virtual void setCaptchaFetcher(CaptchaFetcher* fetcher) = 0;
		virtual CaptchaFetcher* captchaFetcher() const = 0;

		virtual void getCaptcha(const ThreadId& threadId) = 0;
		virtual void makePost(const PostDescriptor& post, const QString& captcha) = 0;
		virtual void createThread(const PostDescriptor& post, const QString& captcha) = 0;

		virtual void requestBoardIndex(const QString& boardId) = 0;
		virtual void requestThread(const ThreadId& threadId, const PostId& lastPostId) = 0;
		virtual void requestThumbnail(const PostId& postId, int attachmentIndex, const QUrl& thumblink) = 0;
		virtual void requestPic(const PostId& postId, int attachmentIndex, const QUrl& piclink) = 0;
		virtual void downloadFile(const PostId& postId, int attachmentIndex,
								  const QUrl& filelink, const QString& filename) = 0;

		virtual void deleteThread(const ThreadId& threadId, const QString& password) = 0;
		virtual void deletePost(const PostId& postId, const QString& password) = 0;

		virtual QStringList contentRatings() = 0;

		virtual ChanAgent* clone(const QString& host) = 0;
		virtual QString id() = 0;

	signals:
		void refresh(ThreadId thread_id, bool indexOnly);
		void postingDone(const ThreadId& thread_id);
		void postingError(const QString& errortype);

		void captcha(const ThreadId& threadId, const QByteArray& c);
		void board(const QString& chanName, const QString& board, const QByteArray& arr);
		void thread(ThreadId thread_id, const QByteArray& arr);
		void threadDead(ThreadId thread_id);
		void thumb(const PostId& postId, int attachIndex, const QByteArray& arr);
		void attachment(const PostId& postId, int attachIndex, const QByteArray& arr, const QString& contentType);

		void pic(const PostId& postId, int attachIndex, const QByteArray& arr);
		void animatedPic(const PostId& postId, int attachIndex, const QByteArray& arr);
	};
}

Q_DECLARE_INTERFACE(Wishmaster::ChanAgent, "com.googlecode.wishmaster.ChanAgent/1.2")


#endif

